const fs = require("fs")
const execa  = require('execa')

// 读取文件夹名称
const dirs = fs.readdirSync('packages').filter(p=>{
    if(!fs.statSync(`packages/${p}`).isDirectory()){
         return false
    }
    return true
})
// ------并行打包start----------
async function runParaller(dirs , itemFn){
  let result = []
 for(let item of dirs){
    result.push(itemFn(item))
 }
 return Promise.all(result)
}
async function build(target){
 return execa('rollup',['-c','--environment',`TARGET:${target}`],{stdio:"inherit"})
}
//--------并行打包end-----------
//并行打包调用
runParaller(dirs , build).then(res => {
    console.log('成功')
})